# -*- coding: utf-8 -*-

"""
Created on 04/26/2022
exp_data_fig.
@author: Kang Xiatao (kangxiatao@gmail.com)
"""

import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import numpy as np
import xlrd, xlwt


is_legend = True
is_outlier = False
fontsize = 20
title = 't'

data_baseline = 0.994
min_y, max_y = 0.98, 0.995

prune_ratio = [0.90, 0.95, 0.98]
label = ['gcs', 'grasp', 'snip']
label_class = label

# 保留部分
data1 = [3080.6196, 1953.5806, 1052.5326]
data2 = [2362.1770, 1533.5229, 836.6000]
data3 = [2959.7698, 1879.8524, 1024.3783]
# 移除部分
data11 = [6907.2031, 8033.1025, 8939.6982]
data22 = [7625.6455, 8453.1602, 9155.6299]
data33 = [7028.0532, 8106.8301, 8967.8516]
# 全部
# data11 = [data1[i]+data11[i] for i in range(len(data2))]
# data22 = [data2[i]+data22[i] for i in range(len(data2))]
# data33 = [data3[i]+data33[i] for i in range(len(data2))]


# 作图
class PltClass(object):

    def __init__(self, xpixels=500, ypixels=500, dpi=None):
        import matplotlib.pyplot as plt
        plt.rcParams['axes.unicode_minus'] = False  # -
        plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
        plt.rc('font', family='Times New Roman')
        if dpi is None:
            plt.figure(1)
        else:
            xinch = xpixels / dpi
            yinch = ypixels / dpi
            plt.figure(figsize=(xinch, yinch))
        self.plt = plt
        # self.color = ['red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'purple', 'pink', 'coral', 'gold', 'lime', 'navy', 'teal', 'indigo']
        self.color = ['red', 'green', 'blue', 'cyan', 'purple', 'pink', 'coral', 'gold', 'lime', 'navy', 'teal', 'indigo']


linewidth = 2
fig = PltClass(xpixels=600, ypixels=300, dpi=60)
fig.plt.plot(prune_ratio, data1, color=fig.color[0], linestyle='-', linewidth=linewidth, alpha=0.8, label=label[0])
fig.plt.plot(prune_ratio, data2, color=fig.color[1], linestyle='-', linewidth=linewidth, alpha=0.8, label=label[1])
fig.plt.plot(prune_ratio, data3, color=fig.color[2], linestyle='-', linewidth=linewidth, alpha=0.8, label=label[2])
# fig.plt.plot(prune_ratio, data11, color=fig.color[0], linestyle='-', linewidth=linewidth, alpha=0.8, label=label[0])
# fig.plt.plot(prune_ratio, data22, color=fig.color[1], linestyle='-', linewidth=linewidth, alpha=0.8, label=label[1])
# fig.plt.plot(prune_ratio, data33, color=fig.color[2], linestyle='-', linewidth=linewidth, alpha=0.8, label=label[2])


fig.plt.title(title, fontsize=fontsize)
fig.plt.xlabel('Pruning ratio', fontsize=fontsize)
fig.plt.ylabel('Norm', fontsize=fontsize)

plt.legend()
fig.plt.tick_params(labelsize=fontsize)
fig.plt.subplots_adjust(left=0.12, right=0.97, top=0.90, bottom=0.15)
fig.plt.grid(linestyle=':')  # 生成网格
if is_outlier:
    fig.plt.ylim([min_y, max_y])
fig.plt.show()
